<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:nwisdocs="http://wales.nhs.uk/nwis/docs"
	exclude-result-prefixes="xs xsi">

  <xsl:template name="allergies">
    <div class="boxed-section" id="{local-name()}">
      <h2>Allergies, intolerances and other risks</h2>

      <div class="inline-content allergy-risk-container">
        
        <h3>Allergies</h3>
        <xsl:choose>
          <xsl:when test="nwisdocs:DocumentBody/nwisdocs:RisksWarnings/nwisdocs:Allergies/nwisdocs:AllergiesStatement/nwisdocs:ClinicalCircumstanceDescription ='Known Allergies'">
            <ul>
              <xsl:for-each select="nwisdocs:DocumentBody/nwisdocs:RisksWarnings/nwisdocs:Allergies/nwisdocs:AllergyAdverseReactions/nwisdocs:AllergyAdverseReaction">
                <li>
                  <xsl:value-of select="nwisdocs:Narrative"/>
                </li>
              </xsl:for-each>
            </ul>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="nwisdocs:DocumentBody/nwisdocs:RisksWarnings/nwisdocs:Allergies/nwisdocs:AllergiesStatement/nwisdocs:ClinicalCircumstanceDescription"/>
          </xsl:otherwise>
        </xsl:choose>
       
        <xsl:choose>
          <xsl:when test="count(nwisdocs:DocumentBody/nwisdocs:RisksWarnings/nwisdocs:Intolerances/*) &gt; 0">
            <h3>Intolerances</h3>
            <ul>
              <xsl:for-each select="nwisdocs:DocumentBody/nwisdocs:RisksWarnings/nwisdocs:Intolerances/nwisdocs:Intolerance">
                <li><xsl:value-of select="nwisdocs:Narrative"/></li>
              </xsl:for-each>
            </ul>
          </xsl:when>
          <xsl:otherwise></xsl:otherwise>
        </xsl:choose>


        <xsl:choose>
          <xsl:when test="count(nwisdocs:DocumentBody/nwisdocs:RisksWarnings/nwisdocs:Risks/*) &gt; 0">
            <h3>Other risks</h3>
            <ul>
              <xsl:for-each select="nwisdocs:DocumentBody/nwisdocs:RisksWarnings/nwisdocs:Risks/nwisdocs:Risk">
                <li>
                  <xsl:value-of select="nwisdocs:Narrative"/>
                </li>
              </xsl:for-each>
            </ul>
          </xsl:when>
          <xsl:otherwise></xsl:otherwise>
        </xsl:choose>
      </div>
    </div>
  </xsl:template>
</xsl:stylesheet>
